package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import excepcion.DAOExcepcion;
import modelo.Categoria;
import modelo.mBanco;
import util.ConexionBD;

public class daoBanco extends BaseDAO {

	public Collection<mBanco> listar() throws DAOExcepcion {
		Collection<mBanco> c = new ArrayList<mBanco>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBD.obtenerConexion();
			String query = "select idBanco, txNombre from banco";
			stmt = con.prepareStatement(query);
			rs = stmt.executeQuery();
			while (rs.next()) {
				mBanco vo = new mBanco();
				vo.setIdBanco(rs.getInt(1));
				vo.setTxBanco(rs.getString(2));
				c.add(vo);
			}

		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return c;
	}

}
